// Copyright 2013 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// A simple tool to help convert RGB <--> HSV via command line

#include <iostream>
#include "compat.h"
#include "colorspace_conversions_ex.h"

DEFINE_int32(R, -1, "R value in RGB space");
DEFINE_int32(G, -1, "G value in RGB space");
DEFINE_int32(B, -1, "B value in RGB space");

DEFINE_double(H, -1, "H value in HSV space");
DEFINE_double(S, -1, "S value in HSV space");
DEFINE_double(V, -1, "V value in HSV space");

int main(int argc, char **argv) {
  google::ParseCommandLineFlags(&argc, &argv, true);


  // Either supply RGB or HSV values. If both, use RGB
  CHECK(((-1 != FLAGS_R) && (-1 != FLAGS_G) && (-1 != FLAGS_B)) ||
        ((-1 != FLAGS_H) && (-1 != FLAGS_S) && (-1 != FLAGS_V)));

  uint8 r, g, b;
  double h, s, v;

  if (-1 != FLAGS_R) {
    // Convert RGB to HSV
    harmonizer::ConvertRGBToHSV(FLAGS_R, FLAGS_G, FLAGS_B,
                                &h, &s, &v);
    std::cout << "RGB(" << FLAGS_R << ", " << FLAGS_G << ", " <<
          FLAGS_B << ") --> HSV(" << h << ", " << s << ", " << v << ")" <<
          std::endl;
  } else {
    // Convert HSV to RGB
    harmonizer::ConvertHSVToRGB(FLAGS_H, FLAGS_S, FLAGS_V,
                                &r, &g, &b);
    std::cout << "HSV(" << FLAGS_H << ", " << FLAGS_S << ", " <<
          FLAGS_V << ") --> RGB(" << static_cast<uint>(r) << ", " <<
          static_cast<uint>(g) << ", " << static_cast<uint>(b) << ")" <<
          std::endl;
  }

  return 0;
}
